package com.xuhao.didi.oksocket.data;

import com.google.gson.JsonObject;
import com.xuhao.didi.core.iocore.interfaces.IPulseSendable;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.charset.Charset;

public class PulseBean implements IPulseSendable {
    private String str = "";

    /**
     * 构造
     */
    public PulseBean() {
        JsonObject jsonObject = new JsonObject();
        jsonObject.addProperty("cmd", 14);
        str = jsonObject.toString();
    }

    @Override
    public byte[] parse() {
        byte[] body = str.getBytes(Charset.defaultCharset());
        ByteBuffer bb = ByteBuffer.allocate(4 + body.length);
        bb.order(ByteOrder.BIG_ENDIAN);
        bb.putInt(body.length);
        bb.put(body);
        return bb.array();
    }
}